﻿module ParseAndRender

open System.Windows.Media
open NUnit.Framework
open BrowserWindow
open RenderingContext
open Rendering
open Layout
open DummyHost
open Dom
open HtmlDom
open UriParsing
open HttpInterfaces


[<TestFixture>]
type testIntegration() = 
    (* Integration - parses html and renders *)

    member this.parseAndRender (html:string) =
    
        let render (doc:Document) (viewportSize:int*int) (c:RenderingContext) = 
            let width, height = viewportSize
            let availWidth = max width 600
            let layout = layoutRoot (doc.documentElement) availWidth
            renderLayout ((0,0),layout) c 
            layout

        let renderPage (doc:Document) = 

            let drawingVisual = DrawingVisual()
            let drawingContext = drawingVisual.RenderOpen();

            // render
            let layout = render doc (600,600) (new RenderingContext(drawingContext, new System.Windows.Point(0.0,0.0)))
            drawingContext.Close()

        let dummyNavigator uri = async { return ResponseOption.Failure("") }
        let controller = BrowserWindow(renderPage, DummyLoader(), (fun(txt)->()), dummyNavigator)
        controller.loadDocument(blankUri, html)

    [<Test>]
    member this.testSimple() =
        this.parseAndRender @"<title>test</title>Hello"
        (*
    [<Test>]
    member this.testDefaultDoc() =
        this.parseAndRender defaultHtml
        *)